//
//  XHTabBar.m
//  围脖
//
//  Created by 魏兴浩 on 15/12/14.
//  Copyright © 2015年 wxh. All rights reserved.
//

#import "XHTabBar.h"

@implementation XHTabBar
-(void)layoutSubviews{
    [super layoutSubviews];
    [self prepareUI];
}
//准备UI
-(void)prepareUI{
    //设置宽度
    CGFloat writeBtnW = self.bounds.size.width/5;
    //设置高度
    CGFloat writeBtnH = self.bounds.size.height;
    //设置frame
    CGRect writeFrame = CGRectMake(0, 0, writeBtnW, writeBtnH);
    //设置index
    int index = 0;
    //遍历self.subviews
//    for (UIView *views in self.subviews) {
//        //判断是否是UIControl 并且是不是UIButton，条件满足就执行
//        if ([views isKindOfClass:[UIControl class]] && ![views isKindOfClass:[UIButton class]]) {
//         views.frame = CGRectOffset(writeFrame, index * writeBtnW, 0);
//        }
//    }
                index += index == 1 ? 2 : 1;
    self.writeBtn.frame = CGRectOffset(writeFrame, 2 * writeBtnW, 0);
}
#pragma 撰写按钮点击事件
-(void)writeBtnClick{
    NSLog(@"点击撰写按钮");
}
#pragma mark -懒加载
-(UIButton *)writeBtn{
    if (!_writeBtn) {
        _writeBtn = [[UIButton alloc]init];
        //设置撰写按钮的背景图片
        [_writeBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [_writeBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        
        //设置撰写按钮的点击图片
        [_writeBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [_writeBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        //添加点击事件
        [_writeBtn addTarget:self action:@selector(writeBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_writeBtn];
    }
    return _writeBtn;
}
@end
